{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b5c926dc",
   "metadata": {},
   "source": [
    "# Node2Vec 官方作者Aditya Grover代码解读"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5c4c2bef",
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import argparse\n",
    "import numpy as np\n",
    "import networkx as nx\n",
    "from gensim.models import Word2Vec\n",
    "import random\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "854a549a",
   "metadata": {},
   "source": [
    "## 读入命令行参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "82b3a4f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "def parse_args():\n",
    "    '''\n",
    "        Parses the node2vec arguments.\n",
    "    '''\n",
    "    # 使用parser加载信息\n",
    "    parser = argparse.ArgumentParser(description=\"Run node2vec\")\n",
    "    # 输入文件：邻接表\n",
    "    parser.add_argument('--output', nargs='?',default='karate.emb',help='Embeddings path')\n",
    "    # Embedding嵌入向量维度\n",
    "    parser.add_argument('--dimensions',type=int, default=128, help='Number of dimensions. Default is 128.')\n",
    "    # 随机游走序列长度\n",
    "    parser.add_argument('--walk-length', type=int,default=80,help='Length of walk per source. Default is 80')\n",
    "    # 每个节点生成随机游走序列次数\n",
    "    parser.add_argument('--num-walks',type=int,default=10,help='Number of walks per source. Default is 10.')\n",
    "    # word2vec窗口大小，word2vec参数\n",
    "    parser.add_argument('--window-size',type=int,default=10,help='Context size for optimization. Default is 10.')\n",
    "    # SGD优化时epoch数量，Word2vec参数\n",
    "    parser.add_argument('--iter',type=int,default=1,help='Number of epochs in SGD')\n",
    "    # 并行化核数，word2vec参数\n",
    "    parser.add_argument('--workers',type=int,default=8  ,help='Number of parallel workers. Default is 8.')\n",
    "    # p\n",
    "    parser.add_argument('--p',type=float,default=1,help='Return hyperparameter. Default is 1.')\n",
    "    # q\n",
    "    parser.add_argument('--q',type=float,default=2,help='InOut hyperparameter.Default is 2.')\n",
    "    # 连接是否带权重\n",
    "    parser.add_argument('--weighted',dest='weighted',action='store_true',help='Boolean specifying (un)weighted. Default is unweighted')\n",
    "    parser.add_argument('--unweighted',dest='unweighted',action='store_false')\n",
    "    # 有向图还是无向图\n",
    "    parser.add_argument('--directed',dest='directed',action='store_true',help='Graph is (un)directed. Default is undirected.')\n",
    "    parser.add_argument('--undirected',dest='unweighted',action='store_false')\n",
    "    parser.set_defaults(directed=False)\n",
    "    return parser.parse_args(args=[])\n",
    "\n",
    "args = parse_args()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "38fdac77",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27b16bd8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
